#!/usr/bin/env python

from os import getenv

if __name__ == '__main__':
	print 'Getting env variables'
	total_nodes = int(getenv('total_nodes'))
	output_name = getenv('output_name')
	template = getenv('template')
	
	print 'Reading template {}'.format(template)
	rep = None
	with open(template, 'r') as f:
		rep = f.read()
	
	for i in range(1, total_nodes + 1):
		print 'Creating olsr config for node-{}'.format(i)
		current = rep.replace('@NN@', str(i))
		with open(output_name.format(node_id=i), 'w') as f:
			f.write(current)
